package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author： pang-yun
 * @date： 2021-11-26 14:47
 * 功能目的 ：用于 使用
 */

public class RequestDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求的 资源路径
        System.out.println(req.getRequestURI());
        // 获取请求得  绝对路径
        System.out.println(req.getRequestURL());

        System.out.println(req.getParameterMap());
        System.out.println(req.getParameter("user"));
        System.out.println(req.getParameter("password"));
        System.out.println(req.getParameter("hobby"));

//        /javaWeb/request
//        http://localhost:9999/javaWeb/request
//        pang
//        123
//        swim
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 接收汉字时 需要 utf -8 编码
        req.setCharacterEncoding("utf-8");
        System.out.println(req.getParameterMap());
        System.out.println(req.getParameter("username"));
        System.out.println(req.getParameter("password"));
        System.out.println(req.getParameter("hobby"));

    }
}
